﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
//using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class UserBackGround_InfoAddInterface : System.Web.UI.Page
{
    Operation operation = new Operation();　//声明业务层类对象
    FCKLoadedManager mg;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["username"] == null)
            {
                Response.Redirect("~/UserLogin.aspx");
            }
            mg = new FCKLoadedManager(Session["userid"].ToString());
            mg.deleteImages();
            DataSet ds = operation.SelectUserInfo(Session["userid"].ToString());
            txtLinkMan.Text = ds.Tables[0].Rows[0][1].ToString();
            txtTel.Text = ds.Tables[0].Rows[0][5].ToString();
            tbEmail.Text = ds.Tables[0].Rows[0][4].ToString();
            tbTel.Text = tbPhone.Text = txtTel.Text;
            tbPrjMan.Text = txtLinkMan.Text;
            tbComName.Text = ds.Tables[0].Rows[0][10].ToString();
            tbAddress.Text = ds.Tables[0].Rows[0][11].ToString();
            tbComInfo.Text = ds.Tables[0].Rows[0][12].ToString();
            BuildList(new object(), new EventArgs());
        }
    }

    protected void imgBtnAdd_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["userid"] == null)
        {
            WebMessageBox.Show("会话已经失效，请重新登录！");
            return;
        }
        int userid = Convert.ToInt32(Session["userid"]);
        if (one.SelectedValue.IndexOf("技术") != -1)
        {
            string typeid = dlCategory.SelectedValue;
            if (typeid.Length <= 0) typeid = "0";
            if (one.SelectedValue.IndexOf("需求") != -1)
            {
                operation.InsertXQInfo(one.Text,tbComName.Text.Trim(), tbPrjName.Text.Trim(), tbPrjMan.Text.Trim(), tbDept.Text.Trim(), tbRanks.Text.Trim(),
                    tbAddress.Text.Trim(), tbPostCode.Text.Trim(), tbTel.Text.Trim(), tbPhone.Text.Trim(), tbFx.Text.Trim(), tbEmail.Text.Trim(),
                    tbWayReq.Text.Trim(), tbComInfo.Text.Trim(), tbProblem.Text.Trim(), tbNewPrd.Text.Trim(), tbWill.Text.Trim(), typeid, userid.ToString());
            }
            else
            {
                mg = new FCKLoadedManager(Session["userid"].ToString());
                mg.deleteImgBeforeInsert(txtInfo.Value.Trim());
                //Response.Write(mg.getFileListFromInfo(txtInfo.Value.Trim()));
                operation.InsertInfo(one.Text, txtTitle.Text.Trim(), txtInfo.Value.Trim(),
                        txtLinkMan.Text.Trim(), txtTel.Text.Trim(), userid, typeid);
            }
        }
        else
        {
            //Response.Write("<script language=javascript>alert('PB！');</script>");
            operation.InsertInfo(one.Text, txtTitle.Text.Trim(), txtInfo.Value.Trim(), txtLinkMan.Text.Trim(), txtTel.Text.Trim(), userid, "0");
        }
        WebMessageBox.Show("信息发布成功！", "UnCheckInfo.aspx");
    }
    public void BuildList(object sender, EventArgs e)
    {
        this.notXQInfoPanel.Visible = true;
        this.XQInfoPanel.Visible = false;
        if (one.Text.IndexOf("技术") == -1)
        {
            dlCategory.Visible = false;
        }
        else
        {
            if (one.Text.IndexOf("需求") != -1)
            {
                this.notXQInfoPanel.Visible = false;
                this.XQInfoPanel.Visible = true;
            }
            dlCategory.Visible = true;
            dlCategory.Items.Clear();
            BuildDownList("0", "", "---");
        }
    }
    public void BuildDownList(string pid, string itH, string dx)//itH为表项前度，dx为递增前度
    {
        DataSet ds = operation.SelectCategoryByPID(pid,true);//一级类别
        int count = ds.Tables[0].Rows.Count;
        string t = itH + dx;//下级前度
        for (int i = 0; i < count; i++)
        {
            ListItem item = new ListItem();
            item.Value = ds.Tables[0].Rows[i][0].ToString();
            item.Text = itH + ds.Tables[0].Rows[i][1].ToString();
            dlCategory.Items.Add(item);
            BuildDownList(item.Value, t, dx);
        }
    }
}
